<template>
    <div class="bayWindowList">
        <div class="bayWindowListLeft">
            <div v-show="index == 0" v-for="item, index in listLeft" :key="index" class="bayWindow email"
                :class="item.isClose ? 'closeEmail' : 'email'" @click.stop="jumpPage(item)">
                <div class="closeBtn" @click.stop="item.isClose = true"><i class="el-icon-circle-close"></i>关闭</div>
                <div class="emailImg">
                    <img :src="item.imgUrl" alt="">
                </div>
                <div class="bayList" v-show="index>0" @click.stop="jumpPage(item)" v-for="item, index in listLeft" :key="index">
                    <div class="emailImg">
                        <img :src="item.imgUrl" alt="">
                    </div>
                </div>
                <div class="openEmail" :class="item.isClose ? '' : 'closeBtn'" @click.stop="item.isClose = false">
                    <i class="el-icon-caret-right"></i>
                </div>
            </div>
        </div>
        <div class="bayWindowListRight">
            <div v-show="index == 0" v-for="item, index in listRight" :key="index" class="bayWindow email"
                :class="item.isClose ? 'closeEmail' : 'email'" @click.stop="jumpPage(item)">
                <div class="closeBtn" @click.stop="item.isClose = true">关闭 <i class="el-icon-circle-close"></i></div>
                <div class="emailImg">
                    <img :src="item.imgUrl" alt="">
                </div>
                <div class="bayList" v-show="index>0"  @click.stop="jumpPage(item)" v-for="item, index in listRight" :key="index">
                    <div class="emailImg">
                        <img :src="item.imgUrl" alt="">
                    </div>
                </div>
                <div class="openEmail rightopenEmail" :class="item.isClose ? '' : 'closeBtn'"
                    @click.stop="item.isClose = false">
                    <i class="el-icon-caret-left"></i>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import $baseUrl from '@/utils/baseURL';
import homepageApi from '@/api/homepage';
export default {
    name: 'bayWindow',
    components: {},
    data() {
        return {
            isPpenBayListRight: false,
            isPpenBaylistLeft: false,
            isClose: false,
            list: [],
            listLeft: [],
            listRight: []

        }
    },
    mounted() {
        this.queryBayWindow();
    },
    methods: {
        async queryBayWindow() {
            let { data: list } = await homepageApi.queryBayWindow({})
            this.list = list || []
            this.list = this.list.map(item => {
                return {
                    ...item,
                    isClose: false,
                    imgUrl: `${$baseUrl.fileServiceUrl}portalWebsite/files/download?fileId=${item.filesId}`
                }
            })
            this.listLeft = this.list.filter(item => { return item.displayLocation == 'LEFT' });
            this.listRight = this.list.filter(item => { return item.displayLocation == 'RIGHT' });
        },
        jumpPage(item) {
            if (item.jumpType == 'URL' && item.url) {
                // 在当前窗口打开新链接
                window.open(item.url, '_blank');
            } else if (item.jumpType == 'ARTICLE' && item.articleId) {
                this.$router.push({
                    path: '/navigation', query: {
                        articleId: item.articleId,
                        name: '文章'
                    }
                })
            } else {
                console.log('无跳转')
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.bayWindowListLeft,
.bayWindowListRight {
    width: 0px;
    position: fixed;
    z-index: 999;
    top: 50%;
    transform: translateY(-50%);

    .closeEmail {
        transform: translateX(-210px);

        .openEmail {
            opacity: 1;
        }
    }
}

.bayWindowListLeft {
    left: 0;

    .closeBtn {
        width: 210px;
        text-align: left;
    }



}

.bayWindowListRight {
    right: 210px;

    .closeEmail {
        transform: translateX(210px);

        .openEmail {
            opacity: 1;
        }
    }

    .closeBtn {
        width: 210px;
        text-align: right;
    }
}

.email {
    font-size: 14px;
    text-align: left;
    font-weight: bold;
    margin-bottom: 10px;
    transition: all 0.2s;
    position: relative;
    cursor: pointer;

    .emailImg {
        margin-top: 10px;

        img {
            width: 210px;
            height: 80px;
            border: 1px solid #cecece;
        }
    }

    .openEmail {
        position: absolute;
        right: -225px;
        top: 40%;
        width: 15px;
        height: 60px;
        background-color: #3e73c7;
        font-size: 12px;
        color: #ffffff;
        border-radius: 0 4px 4px 0;
        line-height: 60px;
        text-align: center;
        transition: all 0.2s;
        opacity: 0;
    }

    .rightopenEmail {
        left: -15px;
        border-radius: 4px 0 0 4px;
    }
}

.open {
    width: 210px;
    color: #ffffff;
    padding: 10px 0;
    text-align: center;
    background-color: #3e73c7;
}
</style>